package com.bw.test_reflect_annotation

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import java.lang.reflect.ParameterizedType

class MainActivity : AppCompatActivity() {
    @Override
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        //1:获得class对象
        val clazz = Class.forName("com.bw.test_reflect_annotation.Student")
        //2:获得构造方法对象
        val constructor = clazz.getDeclaredConstructor(Int::class.java, String::class.java)
        val student = constructor.newInstance(17, "张三") as Student
        //3:获得属性对象
        val field = clazz.getDeclaredField("age")
        field.isAccessible = true
        field.set(student, 18)
        val age = field.get(student)
        println("age: $age")
        //4:获得方法对象
        val method = clazz.getDeclaredMethod("show", String::class.java)
        method.isAccessible = true
        val result = method.invoke(student, "张三")
        println("result: $result")

        //-------------------------------
        //1:获得所有的属性
        val declaredFields = clazz.declaredFields
        for (field in declaredFields) {
            //2：是否为参数化类型
            val type = field.genericType
            if (type is ParameterizedType){
                println("属性名：${field.name} 是参数化类型")
                //3:获得类型以及泛型类型
                val rawType = type.rawType //类型
                val typeArguments = type.actualTypeArguments //泛型
                for (typeArgument in typeArguments) {
                    println("类型：$rawType, 泛型类型：$typeArgument")
                }
            }else{
                println("属性名：${field.name} 不是参数化类型")
            }
        }
        //---------CallAdapter转换器(将retrofit返回Call对象适配...)
        /**
         * RxjavaCallAdapterFactory：设置Rxjava转换器 Call--->Observable
         * LiveDataCallAdapterFactory：设置LiveData转换器 Call--->LiveData
         * 协程：不需要设置转换器，retrofit挂起函数，自动调用内置转换器，不需要额外设置转换器
         */


    }




}